<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="content">
        <h5>多项式求值</h5>
        阶数：<input id="n" type="number" /><br />
        定点：<input id="x" type="number"><br />
        系数：<input id="coefs" type="text"><br />
        <button onclick="cal()">计算！</button>
        <p id="result"></p>
    </div>

</body>
<script>
    function cal() {
        var n = document.getElementById('n').value;
        var x = document.getElementById('x').value;
        var node = document.getElementById('coefs');
        var result = document.getElementById('result');

        var sum = 0;
        var array = node.value.split(' ');
        // console.log(n.value);
        for (let i = 0; i <= n; i++) {
            sum += array[i] * Math.pow(x, i); 
        }
        result.innerHTML = sum.toFixed(1);
    }
</script>
</html>